import request from '@/commons/libraries/request'

export default {
  async getUserMenu () {
    try {
      const ret = await request('/index/menu/', {})
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async gets () {
    try {
      const ret = await request('/setting/sys/menu/gets/', {})
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async get (id) {
    try {
      const ret = await request('/setting/sys/menu/get/', {
        id: id
      })
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async topMenus (level) {
    try {
      const ret = await request('/setting/sys/menu/topMenus/', {
        level: level
      })
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async upMenus (level, top) {
    try {
      const ret = await request('/setting/sys/menu/upMenus/', {
        level: level,
        top: top
      })
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async add (menu) {
    try {
      const ret = await request('/setting/sys/menu/add/', menu)
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  },
  async edit (menu) {
    try {
      const ret = await request('/setting/sys/menu/edit/', menu)
      return ret
    } catch (err) {
      return Promise.reject(new Error(`系统错误，请稍后再试！<br/>[${err.message}]`))
    }
  }
}
